<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE topic
  PUBLIC "-//OASIS//DTD DITA Composite//EN" "ditabase.dtd">
<topic id="topic1" xml:lang="en"><title id="hr138336">pg_stat_last_operation</title><body><p>The pg_stat_last_operation table contains metadata tracking information
about database objects (tables, views, etc.).</p><table id="hr138428"><title>pg_catalog.pg_stat_last_operation</title><tgroup cols="4"><colspec colnum="1" colname="col1" colwidth="131pt"/><colspec colnum="2" colname="col2" colwidth="100pt"/><colspec colnum="3" colname="col3" colwidth="82pt"/><colspec colnum="4" colname="col4" colwidth="136pt"/><thead><row><entry colname="col1">column</entry><entry colname="col2">type</entry><entry colname="col3">references</entry><entry colname="col4">description</entry></row></thead><tbody><row><entry colname="col1"><codeph id="hr138551">classid</codeph></entry><entry colname="col2">oid</entry><entry colname="col3">pg_class.oid</entry><entry colname="col4">OID of the system catalog containing the object.
</entry></row><row><entry colname="col1"><codeph id="hr138559">objid</codeph></entry><entry colname="col2">oid</entry><entry colname="col3">any OID column</entry><entry colname="col4">OID of the object within its system catalog.</entry></row><row><entry colname="col1"><codeph id="hr138567">staactionname</codeph></entry><entry colname="col2">name</entry><entry colname="col3"/><entry colname="col4">The action that was taken on the object.</entry></row><row><entry colname="col1"><codeph id="hr138575">stasysid</codeph></entry><entry colname="col2">oid</entry><entry colname="col3">pg_authid.oid</entry><entry colname="col4">A foreign key to pg_authid.oid.</entry></row><row><entry colname="col1"><codeph id="hr138583">stausename</codeph></entry><entry colname="col2">name</entry><entry colname="col3"/><entry colname="col4">The name of the role that performed the operation
on this object.</entry></row><row><entry colname="col1"><codeph id="hr138447">stasubtype</codeph></entry><entry colname="col2">text</entry><entry colname="col3"/><entry colname="col4">The type of object operated on or the subclass
of operation performed.</entry></row><row><entry colname="col1"><codeph id="hr138456">statime</codeph></entry><entry colname="col2">timestamp with timezone</entry><entry colname="col3"/><entry colname="col4">The timestamp of the operation. This is the same timestamp that is written to
              the Greenplum Database server log files in case you need to look up more
              detailed information about the operation in the logs.</entry></row></tbody></tgroup></table>

    <p>The <codeph>pg_stat_last_operation</codeph> table contains metadata tracking
      information about operations on database objects. This information includes the
      object id, DDL action, user, type of object, and operation timestamp. Greenplum
      Database updates this table when a database object is created, altered,
      truncated, vacuumed, analyzed, or partitioned, and when privileges are granted
      to an object.</p>
    <p>If you want to track the operations performed on a specific object, use the
      <codeph>objid</codeph> value. Because the <codeph>stasubtype</codeph> value can
      identify either the type of object operated on or the subclass of operation
      performed, it is not a suitable parameter when querying the
      <codeph>pg_stat_last_operation</codeph> table.</p>
    <p>The following example creates and replaces a view, and then shows how to use
      <codeph>objid</codeph> as a query parameter on the
      <codeph>pg_stat_last_operation</codeph> table.</p>
    <codeblock>testdb=# CREATE VIEW trial AS SELECT * FROM gp_segment_configuration;
CREATE VIEW
testdb=# CREATE OR REPLACE VIEW trial AS SELECT * FROM gp_segment_configuration;
CREATE VIEW
testdb=# SELECT * FROM pg_stat_last_operation WHERE objid='trial'::regclass::oid;
 classid | objid | staactionname | stasysid | stausename | stasubtype |            statime            
---------+-------+---------------+----------+------------+------------+-------------------------------
  1259  | 24735 | CREATE         |       10 | gpadmin    | VIEW       | 2020-04-07 16:44:28.808811+00
  1259  | 24735 | ALTER          |       10 | gpadmin    | SET        | 2020-04-07 16:44:38.110615+00
(2 rows)</codeblock>
    <p>Notice that the <codeph>pg_stat_last_operation</codeph> table entry for the         view <codeph>REPLACE</codeph> operation specifies the <codeph>ALTER</codeph>
      action (<codeph>staactionname</codeph>) and the <codeph>SET</codeph> subtype
      (<codeph>stasubtype</codeph>).</p>
  </body>
</topic>
